(setq python-shell-interpreter "python3")

(use-package lsp-pyright
  :ensure t
  :hook (python-mode . (lambda ()
                         (require 'lsp-pyright)
                         (lsp))))


(add-hook 'python-mode-hook  'linum-mode)
(add-hook 'python-mode-hook  'lsp)

(defun python-run-current-file (&optional directory)
  "Execute the current python file."
  (interactive
   (list (or (and current-prefix-arg
                  (read-directory-name "Run in directory: " nil nil t))
             default-directory)))
  (when (buffer-file-name)
    (let* ((command (concat "python3 " (buffer-file-name)))
           (default-directory directory)
           (compilation-ask-about-save nil))
      (executable-interpret (read-shell-command "Run: " command)))))

(defun python-debug-current-file (&optional directory)
  "Debug the current python file in pdb."
  (interactive
   (list (or (and current-prefix-arg
                  (read-directory-name "Debug in directory: " nil nil t))
             default-directory)))
  (when (buffer-file-name)
    (let* ((command (concat "python3 -m pdb " (buffer-file-name)))
           (default-directory directory)
           (compilation-ask-about-save nil))
      (executable-interpret (read-shell-command "Debug: " command)))))



(add-hook 'python-mode-hook '(lambda () (local-set-key (kbd "<f5>") 'python-run-current-file)))
(add-hook 'python-mode-hook '(lambda () (local-set-key (kbd "<f6>") 'python-debug-current-file)))
